home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 551-575 / disk_563 / kpri / src.lzh / parse.c < prev    next >
C/C++ Source or Header  |  1991-11-01  |  5KB  |  215 lines

  1.  
  2. #include "defs.h"
  3.  
  4. Prototype           void  do_forget_it(void);
  5. Prototype           void  do_print_it(void);
  6. Prototype __regargs void  do_storage_str(SHORT);
  7. Prototype           void  do_storage_list(void);
  8. Prototype           void  do_quit(void);
  9. Prototype __regargs SHORT do_request(UBYTE *, UBYTE *, UWORD *);
  10. Prototype           void  do_filereq(void);
  11. Prototype __regargs void  do_togglegad(struct Gadget *);
  12. Prototype __regargs void  do_all(SHORT);
  13.  
  14. Prototype SHORT pagesize;
  15. Prototype SHORT linelength;
  16. Prototype SHORT quit;
  17. Prototype SHORT split;
  18. Prototype SHORT title;
  19. Prototype SHORT autom;
  20.  
  21. Prototype struct EasyStruct textreq;
  22.  
  23. SHORT pagesize   = 1;
  24. SHORT linelength = 1;
  25. SHORT quit       = 0;
  26. SHORT split      = 0;
  27. SHORT title      = 1;
  28. SHORT autom      = 1;
  29.  
  30. /***********************  textreq ************************************/
  31. const UBYTE titlereq[] = " Some serious question:";
  32.  
  33. struct EasyStruct textreq =
  34. {
  35.   sizeof(struct EasyStruct),            /* ULONG es_StructSize      */
  36.   0l,                                   /* ULONG es_Flags           */
  37.   titlereq,                             /* UBYTE *es_Title          */
  38.   NULL,                                 /* UBYTE *es_TextFormat     */
  39.   NULL,                                 /* UBYTE *es_GadgetFormat   */
  40. };
  41.  
  42. /***********************  do_print_it(void) **************************/
  43. void
  44. do_print_it(void)
  45. {
  46.   if (Buf_storage_str[0] != '\0')
  47.   {
  48.     PE *pe;
  49.     if (pe = (PE *)FindName(&List_storage_list, Buf_storage_str))
  50.     {
  51.       if (init_par(pe))
  52.       {
  53.         if (init_prt())
  54.         {
  55.           do_togglegad(Gad_print_it);
  56.           Write(prt, pe->SplitBuffer, pe->Size);
  57.           close_prt();
  58.           del_prienv(pe);
  59.           do_togglegad(Gad_print_it);
  60.           return;
  61.         }
  62.       }
  63.     }
  64.     do_storage_str(NULL);
  65.   }
  66. }
  67.  
  68. /***********************  do_forget_it(void)  ************************/
  69. void
  70. do_forget_it(void)
  71. {
  72.   if (Buf_storage_str[0])
  73.   {
  74.     PE *pe;
  75.     if (pe = (PE *)FindName(&List_storage_list, Buf_storage_str))
  76.       del_prienv(pe);
  77.     else
  78.       do_storage_str(NULL);
  79.   }
  80. }
  81.  
  82. /***********************  do_quit(void) ******************************/
  83. const UBYTE reallyquit[] = "Really quit now ???";
  84. const UBYTE yescancel[]  = "Yes|Cancel";
  85.  
  86. void
  87. do_quit(void)
  88. {
  89.   do_togglegad(Gad_quit);
  90.   if ((quit = do_request(reallyquit, yescancel, 0)) == 0)
  91.     do_togglegad(Gad_quit);
  92. }
  93.  
  94. /***********************  do_request(UBYTE *) ************************/
  95. __regargs SHORT
  96. do_request(UBYTE *text, UBYTE *gads, UWORD *args)
  97. {
  98.   textreq.es_TextFormat   = text;
  99.   textreq.es_GadgetFormat = gads;
  100.  
  101.   return (EasyRequestArgs(win, &textreq, NULL, &args));
  102. }
  103.  
  104. /***********************  do_storage_list(void) **********************/
  105. void
  106. do_storage_list(void)
  107. {
  108.   PE *pe;
  109.   if (pe = (PE *)FindName(&List_storage_list, Buf_storage_str))
  110.   {
  111.     pagesize   = pe->pagesize;
  112.     linelength = pe->linelength;
  113.  
  114.     GT_SetGadgetAttrs(Gad_pagesize, win, NULL,
  115.                       GTCY_Active, pagesize,
  116.                       TAG_END);
  117.  
  118.     GT_SetGadgetAttrs(Gad_linelength, win, NULL,
  119.                       GTCY_Active, linelength,
  120.                       TAG_END);
  121.   }
  122. }
  123.  
  124. /***********************  do_storage_str(SHORT)  **********************/
  125. __regargs void
  126. do_storage_str(SHORT show)
  127. {
  128.   if (!show)
  129.     Buf_storage_str[0] = '\0';
  130.  
  131.   GT_SetGadgetAttrs(Gad_storage_str, win, NULL,
  132.                     GTST_String, Buf_storage_str,
  133.                     TAG_END);
  134. }
  135.  
  136. /***********************  do_filereq()  **********************/
  137. const UBYTE chooztext[] = "Chooz text to load:";
  138. const UBYTE loadit[]    = "Load it";
  139.  
  140. void
  141. do_filereq(void)
  142. {
  143.   do_togglegad(Gad_filereq);
  144.  
  145.   UBYTE ok = FALSE;
  146.   struct FileRequester *freq;
  147.   if (freq = AllocAslRequestTags(ASL_FileRequest,
  148.                                  ASL_Hail,      chooztext,
  149.                                  ASL_Window,    win,
  150.                                  ASL_LeftEdge,  win->LeftEdge,
  151.                                  ASL_TopEdge,   win->TopEdge,
  152.                                  ASL_Width,     WIN_WIDTH,
  153.                                  ASL_Height,    WIN_HEIGHT,
  154.                                  ASL_OKText,    loadit,
  155.                                  TAG_END))
  156.  
  157.   {
  158.     if (ok = AslRequest(freq, NULL))
  159.     {
  160.       UBYTE *d = Buf_storage_str;
  161.       UBYTE *s = freq->rf_Dir;
  162.       if (*s)
  163.       {
  164.         for (; *d = *s; ++s, ++d);    /*  strcpy dirname  */
  165.  
  166.         --d;
  167.         if  (*d != ':' && *d != '/')
  168.           *++d = '/';
  169.         ++d;
  170.       }
  171.       s = freq->rf_File;
  172.       if (ok = *s)
  173.         for (; *d = *s; ++s, ++d);    /*  strcat filename */
  174.     }
  175.     FreeAslRequest(freq);
  176.   }
  177.   if (ok)
  178.     do_process();
  179.  
  180.   do_storage_str(ok);
  181.  
  182.   do_togglegad(Gad_filereq);
  183. }
  184.  
  185. /***********************  do_togglegad  **************************/
  186. __regargs void
  187. do_togglegad(struct Gadget *gadget)
  188. {
  189.   USHORT gad_pos = RemoveGadget(win, gadget);
  190.  
  191.   if (gadget->Flags & SELECTED)
  192.     gadget->Flags  -= SELECTED;
  193.   else
  194.     gadget->Flags  += SELECTED;
  195.  
  196.   AddGadget(win, gadget, gad_pos);
  197.   RefreshGList(gadget, win, NULL, 1);
  198. }
  199.  
  200. /***********************  do_all() ********************************/
  201. __regargs void
  202. do_all(SHORT side)
  203. {
  204.   PE *pe     = (PE *) List_storage_list.mlh_Head;
  205.   while (pe != (PE *)&List_storage_list.mlh_Tail)
  206.   {
  207.     PE *pet = pe->pe_node.ln_Succ;
  208.     if (pe->pe_node.ln_Type == side)
  209.       ask_print(pe->pe_node.ln_Name);
  210.  
  211.     pe = pet;
  212.   }
  213. }
  214.  
  215.